﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.Server;

namespace TFSTools.TFSLibrary
{
    public class TFSIdentity : TFSServerEntity
    {
        private Identity serverIdentity;

        internal TFSIdentity(ITFSConnection connection, Identity identity)
            : base(connection) 
        {
            this.serverIdentity = identity;
        }

        internal Identity ServerEntity { get { return this.serverIdentity; } }

        public string AccountName { get { return this.serverIdentity.AccountName; } }

        public string Description { get { return this.serverIdentity.Description; } }

        public string DisplayName { get { return this.serverIdentity.DisplayName; } }

        public string DistinguishedName { get { return this.serverIdentity.DistinguishedName; } }

        public string Domain { get { return this.serverIdentity.Domain; } }

        public override string ToString() { return this.serverIdentity.ToString(); }
    }

    public sealed class TFSIdentityCollection : TFSServerEntityCollection<TFSIdentity>
    {
        public TFSIdentityCollection(ITFSConnection connection)
            : base(connection)
        {
        }

        public TFSIdentityCollection(ITFSConnection connection, IList<TFSIdentity> list)
            : base(connection, list)
        {
        }

        public TFSIdentityCollection(ITFSConnection connection, int capacity)
            : base(connection, capacity)
        {
        }

        internal static TFSIdentityCollection Create(ITFSConnection connection, List<Identity> usernames)
        {
            var list = from entity in usernames select new TFSIdentity(connection, entity);

            return new TFSIdentityCollection(connection, list.ToArray());
        }
    }
}
